package cn.iphone.NPlayer.web.controller;
import cn.iphone.NPlayer.dto.SmsCodeDto;
import cn.iphone.NPlayer.result.JSONResult;
import cn.iphone.NPlayer.service.IVerifyCodeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Resource
    private IVerifyCodeService verifyCodeService;

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult image(@PathVariable("imageCodeKey")String imageCodeKey){
        //调用业务代码获取图形验证码（base64编码的字符串）
        String base64Str = verifyCodeService.imageCodeKey(imageCodeKey);
        //将（base64编码的字符串）响应给前端
        return JSONResult.success(base64Str);
    }

    @RequestMapping("/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody @Valid SmsCodeDto smsCodeDto){
        verifyCodeService.sendSmsCode(smsCodeDto);
        return JSONResult.success();
    }
}
